package com.auth.control.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.auth.control.model.UserDto;
import com.auth.domain.module.vo.authmanage.UserAuthVo;
import com.auth.domain.module.vo.authmanage.UserVO;
import com.auth.domain.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * User com.base.control
 *
 * @description: 用户操作
 * @author: cyj
 * @date 2020 -10-21 20:39:21
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "用户")
public class UserControl {

    @Autowired
    private IUserService userService;

    @GetMapping("/all")
    @ApiOperation("获取分页用户")
    public IPage<UserVO> getUsers(Page page) {
        IPage<UserVO> list = userService.pageCommon(page);
        return list;
    }

    @GetMapping("/auth/{id}")
    @ApiOperation("获取用户权限")
    public UserAuthVo getUsers(@PathVariable Long id) {
        UserAuthVo userAuthVo = userService.getAuth(id);
        return userAuthVo;
    }

    @PostMapping
    @ApiOperation("保存用户")
    public UserVO saveUser(@RequestBody UserDto userDto) {
        UserVO userVO = userService.saveUser(userDto);
        return userVO;
    }

    @PutMapping
    @ApiOperation("更新用户")
    public UserVO updateUser(@RequestBody UserDto userDto) {
        UserVO userVO = userService.updateUser(userDto);
        return userVO;
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除用户")
    public UserVO deleteUser(@PathVariable Long id) {
        UserVO userVO = userService.deleteUser(id);
        return userVO;
    }

    @GetMapping("/{id}")
    @ApiOperation("查询用户")
    public UserVO selectUser(@PathVariable Long id) {
        UserVO userVO = userService.selectUser(id);
        return userVO;
    }
}
